package com.yanghui.lingyue.functions.defaultFunction

import com.icedata.sika.bridge.*
import com.icedata.sika.core.CommandProcessor
import com.icedata.sika.core.Sika
import com.yanghui.lingyue.data.Command

object SendMessage {

    private val trigMessage = listOf("TEXT", "FACE", "IMAGE", "AT")

    fun filter(command: Command): Boolean {
        if (command.instruction.split(":")[0] in trigMessage) {
            return true
        }
        return false
    }

    suspend fun execute(command: Command, sika: Sika): CommandProcessor.Result {
        val builder = SikaMessageChainBuilder()
        val commandList = command.instruction.split("&")
        for (c in commandList) {
            when (c.split(":")[0]) {
                "TEXT" -> builder.add(SikaPlainMessage(c.substring(5)))
                "FACE" -> builder.add(SikaFaceMessage(c.substring(5).toInt()))
                "AT" -> builder.add(SikaAtMessage(c.substring(3).toLong()))
                "IMAGE" -> {
                    TODO("发送图片")
                }
            }
        }
        command.sendGroup?.sendMessage(builder)
        return CommandProcessor.Result.ADOPT
    }

}